package org.tgcloud.group.web.controller.manager.project;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;
import org.tgcloud.group.core.APPResultMessage;
import org.tgcloud.group.core.custom.Permissions;
import org.tgcloud.group.core.session.Session;
import org.tgcloud.group.entity.MjProjectShipment;
import org.tgcloud.group.service.manager.ProjectShipmentService;
import org.tgcloud.group.web.controller.dto.project.ProjectQueryDto;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "发货信息")
@RestController
@RequestMapping("/manager/pc/user/shipment")
@EnableAutoConfiguration
public class ProjectShipmentController {

    @Autowired
    private ProjectShipmentService projectShipmentService;


    @ApiOperation(value = "查询")
    @ResponseBody
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    public APPResultMessage query(@ModelAttribute("session") Session session,
                                  @RequestBody ProjectQueryDto dto){
        return projectShipmentService.query(dto);
    }


    @ApiOperation(value = "发货")
    @ResponseBody
    @Permissions("shipment:add")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public APPResultMessage createShipment(@ModelAttribute("session") Session session,
                                         @RequestBody MjProjectShipment projectShipment,
                                         HttpServletRequest request){

        return projectShipmentService.createShipment(projectShipment);
    }

    @ApiOperation(value = "修改")
    @ResponseBody
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public APPResultMessage updateMjProjectShipment(@ModelAttribute("session") Session session,
                                              @RequestBody MjProjectShipment projectShipment){
        return projectShipmentService.updateMjProjectShipment(projectShipment);
    }

    @ApiOperation(value = "详情")
    @ResponseBody
    @RequestMapping(value = "/getDatils", method = RequestMethod.GET)
    public APPResultMessage getDatils(@ModelAttribute("session") Session session,
                                      @RequestParam Integer id){
        return projectShipmentService.getDatils(id);
    }

    @ApiOperation(value = "删除")
    @ResponseBody
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public APPResultMessage delete(@ModelAttribute("session") Session session,
                                   @RequestParam Integer id){
        return projectShipmentService.delete(id);
    }

    @ApiOperation(value = "确认收货")
    @ResponseBody
    @Permissions("shipment:receipt")

    @RequestMapping(value = "/sureShipment", method = RequestMethod.GET)
    public APPResultMessage sureShipment(@ModelAttribute("session") Session session,
                                        @RequestParam Integer projectId){
        return projectShipmentService.sureShipment(projectId);
    }



}
